/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui;

/**
 *
 * @author saul
 */
import configureCharts.GenerateGraphs;
import controlcharts.GenericChartLimits;
import controlcharts.PChartLimits;
import controlcharts.StandardDeviationChartLimits;
import data.DataSetException;
import indices.IndicesDFuncao;
import java.awt.Dimension;
import java.io.File;
import org.jfree.chart.ChartFrame;
import statistic.AverageStatistic;
import statistic.GenericStatistic;
import statistic.PStatistic;
import statistic.StandardDeviationStatistic;
public class PutIndice extends javax.swing.JFrame {

         private ok parent;
    /**
     * Creates new form PutIndice
     */
    public PutIndice(ok parent) {
        this.parent = parent; 
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        textFieldLSE = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        textFieldLIE = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("Variaveis do Indice");

        jButton1.setText("Calcular");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("LSE");

        jLabel3.setText("LIE");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(layout.createSequentialGroup()
                            .addGap(140, 140, 140)
                            .addComponent(jLabel1))
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                            .addGap(114, 114, 114)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGap(30, 30, 30)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(textFieldLSE, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(textFieldLIE, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(132, 132, 132)
                        .addComponent(jButton1)))
                .addContainerGap(112, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addGap(41, 41, 41)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFieldLSE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textFieldLIE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(19, 19, 19)
                .addComponent(jButton1)
                .addContainerGap(42, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

        this.setVisible(false);
        String constante1 = this.textFieldLSE.getText();
        Double constante_LSE = Double.parseDouble(constante1);
        String constante2 = this.textFieldLIE.getText();
        Double constante_LIE = Double.parseDouble(constante2);
       
       GenericStatistic statistic = new StandardDeviationStatistic(true);
       GenericStatistic mediaS = new AverageStatistic();
     //  GenericChartLimits limites = new StandardDeviationChartLimits();
       File arquivo = this.parent.abrirArquivo();
        IndicesDFuncao indice = new IndicesDFuncao(constante_LSE, constante_LIE);
         try {
           indice.acha(statistic, arquivo, mediaS);
           indice.calculaIndices();
           
          parent.jTextArea1.setText("Cp: "+ indice.getCp());
          parent.jTextArea1.append("\n"+ "Cpu: "+indice.getCpu());
          parent.jTextArea1.append("\n"+ "Cpl: "+indice.getCpl());
          parent.jTextArea1.append("\n"+ "Cpk: "+indice.getCpk());
          parent.jTextArea1.append("\n"+ "TAMANHO: "+indice.getTam());
          parent.jTextArea1.append("\n"+ "cn: "+indice.getCn());
          //parent.jTextArea1.append("\n"+ "M: "+indice.getM());
          parent.jTextArea1.append("\n"+ "X: "+indice.getMediaMed());
          parent.jTextArea1.append("\n"+ "d.padrao: "+indice.getMedia());
        } catch (DataSetException e) {
            // TODO tratar essa excessão
            e.printStackTrace();
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JTextField textFieldLIE;
    private javax.swing.JTextField textFieldLSE;
    // End of variables declaration//GEN-END:variables
}
